package com.crm.system.controller.sys;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.entity.sys.permissionManagement.SysCompanyProject;
import com.crm.model.vo.sys.CompanyProjectTVO;
import com.crm.model.vo.sys.CompanyProjectVO;
import com.crm.system.service.sys.CompanyProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:chaifuyou
 * @Date: 2021/7/27 9:15
 */
@RestController
@RequestMapping("/companyProject")
@Slf4j
public class CompanyProjectController {

    @Autowired
    private CompanyProjectService companyProjectService;

    /**
     * 增加分公司项目
     * @return
     */
    @PostMapping("/addCompanyProject")
    public DataResponse addCompanyProject(@RequestBody SysCompanyProject sysCompanyProject){
        companyProjectService.addCompanyProject(sysCompanyProject);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

    /**
     * 修改分公司项目
     * @return
     */
    @PostMapping("/updateCompanyProject")
    public DataResponse updateCompanyProject(@RequestBody SysCompanyProject sysCompanyProject){
        companyProjectService.updateCompanyProject(sysCompanyProject);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

    /**
     * 分页查询分公司项目列表
     * @param pageIndex
     * @param pageSize
     * @param companyName
     * @return
     */
    @PostMapping("/selectCompanyProjectList")
    public DataResponse selectCompanyProjectList(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                 @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                 @RequestParam(value = "companyName", required = false) String companyName,
                                                 @RequestParam(value = "companyId", required = false) String companyId ){
        DhPageInfo<CompanyProjectVO> pageVOList = companyProjectService.selectCompanyProjectList(pageIndex,pageSize,companyName,companyId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),pageVOList);
    }

    /**
     * 分页查询分公司项目列表
     * @param pageIndex
     * @param pageSize
     * @param companyName
     * @return
     */
    @PostMapping("/selectCompanyProjectListT")
    public DataResponse selectCompanyProjectListT(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                                  @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                                  @RequestParam(value = "companyName", required = false) String companyName,
                                                  @RequestParam(value = "companyId", required = false) String companyId ){
        DhPageInfo<CompanyProjectTVO> pageVOList = companyProjectService.selectCompanyProjectListT(pageIndex,pageSize,companyName,companyId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),pageVOList);
    }

    /**
     * 删除项目
     * @param companyProjectId
     * @return
     */
    @PostMapping("/delCompanyProject")
    public DataResponse delCompanyProject(@RequestParam(value = "companyProjectId", required = true) String companyProjectId){
        companyProjectService.delCompanyProject(companyProjectId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

}
